package com.example.testdemo.rxjava_test;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.example.testdemo.R;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

public class EventBusB_Activity extends AppCompatActivity {
    public static final String TAG = "EventBusB_Activity";
    private Button btnSend;
    private TextView textView;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_rxjava_test_a_view);
        btnSend = findViewById(R.id.button);
        textView = findViewById(R.id.textView2);

        EventBus.getDefault().register(this);

        btnSend.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //发送事件
//                EventBus.getDefault().post( "eventbus数据传过来了");
                Intent intent = new Intent(EventBusB_Activity.this, EventBusC_Activity.class);
                startActivity(intent);
            }
        });
    }

    @Subscribe(sticky = true)
    public void onUploadText(String text){
        textView.setText(text);
    }



    @Override
    protected void onDestroy() {
        super.onDestroy();
        EventBus.getDefault().unregister(this);
    }
}
